package com.john.vo;

import com.john.params.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * 通用分页对象
 * 日期 2021/5/27 16:13
 * 创建者：john driver
 */
@Data
@ApiModel(value = "分页结果数据", description = "返回的分页对象")
public class PageVo<T> {
    @ApiModelProperty(value = "分页数据")
    private List<T> records;
    @ApiModelProperty(value = "总条数")
    private Integer total;
    @ApiModelProperty(value = "总页数")
    private Integer pages;
    @ApiModelProperty(value = "当前页")
    private Integer current;
    @ApiModelProperty(value = "查询数量")
    private Integer size;
    @ApiModelProperty(hidden = true)
    public PageVo<T> setCurrentAndSize(PageParam pageForm){
        BeanUtils.copyProperties(pageForm,this);
        return this;
    }
    @ApiModelProperty(hidden = true)
    public void setTotal(Integer total) {
        this.total = total;
        this.setPages(this.total % this.size > 0 ? this.total / this.size + 1 : this.total / this.size);
    }
}
